package com.dapeis.core.utils.json;

import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.ag.utils.DateUtils;
import com.ag.utils.json.AGsonBuilder;
import com.dapeis.core.utils.DBConfigUtils;
import com.dapeis.core.utils.StylistConstants;
import com.dapeis.domain.Collocation;
import com.dapeis.domain.Plan;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

public class PlanGsonAdapter implements JsonSerializer<Plan>{

	@Override
	public JsonElement serialize(Plan src, Type typeOfSrc,
		    JsonSerializationContext context) {
		JsonObject json = new JsonObject();
		json.addProperty("id", src.getId());
		json.addProperty("collocationId", src.getCollocationId());
		json.addProperty("planName", src.getPlanName());
		json.addProperty("content", src.getContent());
		json.addProperty("agreeNum", src.getAgreeNum());
		json.addProperty("awardNum", DBConfigUtils.paserMoney(src.getAwardNum()));
		json.addProperty("agreeValue", src.getAgreeValue());
		if(src.getPublish() == StylistConstants.PlanState.ISSUE){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			json.addProperty("createTime", sdf.format(new Date(src.getCreateTime()*1000)));
		}else if(src.getPublish() == StylistConstants.PlanState.SAVE){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			json.addProperty("createTime", sdf.format(new Date(src.getCreateTime()*1000)));
		}
		json.addProperty("masterImage", src.getMasterImage());
		json.addProperty("publish", src.getPublish());
		json.add("smallImg",AGsonBuilder.create().toJsonTree(DBConfigUtils.paserGarderobe(src.getImageIds())));
		json.addProperty("masterImage", StylistConstants.PASERIMGPATH(src.getMasterImage()));
		return json;
	}
}
